#ifndef CALIBIMGVIEWER_H
#define CALIBIMGVIEWER_H

#include <QtGui/QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QPushButton>
#include <QSlider>
#include <QLabel>
#include <QTableWidget>
#include <QGroupBox>
#include <QRadioButton>
#include <QLineEdit>
#include "imageitem.h"

class CalibImgViewer : public QWidget
{
    Q_OBJECT
    
public:
    CalibImgViewer(QWidget *parent = 0);
    ~CalibImgViewer();

signals:
    void initTimeStamp(PFCMU::timestamp_t value);
    void timeStampChanged(PFCMU::timestamp_t value);
    void camChanged(int value);

public slots:
    void onAddFiles();
    void onRemoveFile();
    void onRefreshView();
    void onSaveImg();
    void onAutoSaveImg();
    void onLoadBatchFiles();
    void onSaveBatchFiles();
    void onFrameChanged(int);
    void onCamsChanged(int);
    void setupViewMatrix(int size);

private:
    void initScene();
    void initWindow();
    void resetFrameSlider(PFCMU::timestamp_t minValue, PFCMU::timestamp_t maxValue);
    void setTimeStampInc();

    QHBoxLayout *mainHLayout;
    QVBoxLayout *viewVLayout;
    QHBoxLayout *viewHLayout;
    QHBoxLayout *playHLayout;
    QHBoxLayout *camsSpliterHLayout;
    QHBoxLayout *framesSpliterHLayout;
    QGridLayout *batchLoadGLayout;
    QGridLayout *batchSaveGLayout;
    QHBoxLayout *saveImgHLayout;
    QVBoxLayout *listVLayout;

    QGroupBox *gbxBatchLoad;
    QLabel *labelBatchFilePrefix;
    QLineEdit *txtBatchFilePrefix;
    QLabel *labelBatchFileStart;
    QLineEdit *txtBatchFileStart;
    QLabel *labelBatchFileEnd;
    QLineEdit *txtBatchFileEnd;
    QLabel *labelBatchFileSuffix;
    QLineEdit *txtBatchFileSuffix;
    QPushButton *buttonLoadBatchFiles;

    QGroupBox *gbxBatchSave;
    QLabel *labelBatchSavePrefix;
    QLineEdit *txtBatchSavePrefix;
    QLabel *labelBatchSaveStart;
    QLineEdit *txtBatchSaveStart;
    QLabel *labelBatchSaveEnd;
    QLineEdit *txtBatchSaveEnd;
    QLabel *labelBatchSaveCount;
    QLineEdit *txtBatchSaveCount;
    QPushButton *buttonSaveBatchFiles;

    QGraphicsScene *captureScene;
    QGraphicsView *captureView;

    QPushButton *buttonViewAll;
    QLabel *labelSingleView;
    QSlider *sliderZoom;
    QSlider *sliderCams;
    QSlider *sliderFrames;
    QLabel *labelCams;
    QLabel *labelFrames;
    QLabel *labelCurrentCam;
    QLabel *labelMinTimeStamp;
    QLabel *labelMaxTimeStamp;
    QLabel *labelCurrentTimeStamp;
    QGroupBox *gbxFps;
    QHBoxLayout *fpsHLayout;
    QRadioButton *rdo25Fps;
    QRadioButton *rdo100Fps;
    QTableWidget *fileList;
    QPushButton *buttonAddFile;
    QPushButton *buttonRemoveFile;
    QPushButton *buttonRefresh;
    QPushButton *buttonSaveImg;
    QLineEdit *txtImgBaseName;
    QLineEdit *txtImgSaveCount;
    QPushButton *buttonAutoSaveImg;

    PFCMU::timestamp_t m_MinFileGroupTimeStamp;
    PFCMU::timestamp_t m_MaxFileGroupTimeStamp;
    int TIMESTAMPINC;

    int m_BatchSaveCount;
};

#endif // CALIBIMGVIEWER_H
